package jd.se.login;


import jd.se.common.Utils;
import org.apache.ibatis.session.SqlSession;


/**
 * @author SunJiahao
 * @date 2021-05-15 14:55
 */

public class LoginService  {
    public boolean checkLogin(LoginDto dto) {

        SqlSession sqlSession = Utils.openSession();

        try{
            LoginDao dao = sqlSession.getMapper(LoginDao.class);
            int count = dao.findUserCountByIdAndPwd(dto);

            sqlSession.commit();

            return count > 0;
        }catch(Exception e){
            sqlSession.rollback();
            throw new RuntimeException(e);
        }finally{
            sqlSession.close();
        }
    }

    public boolean checkAdmin(LoginDto dto) {
        SqlSession sqlSession = Utils.openSession();

        try{
            LoginDao dao = sqlSession.getMapper(LoginDao.class);
            int count = dao.checkAdmin(dto);
            sqlSession.commit();
            return count > 0;
        }catch(Exception e){
            sqlSession.rollback();
            throw new RuntimeException(e);
        }finally{
            sqlSession.close();
        }
    }
}
